package com.feng.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.feng.dao.ISentenceDao;
import com.feng.dao.SentenceDao;
import com.feng.entity.Sentence;
import com.feng.service.ISentenceService;
import com.feng.util.CommonUtils;
import com.feng.util.PageUtil;

@Service
public class SentenceServiceImpl implements ISentenceService {

	@Autowired
	private SentenceDao sentenceDao;
	@Autowired
	private ISentenceDao iSentenceDao;
	@Override
	public void batchInsert(List<Sentence> setences) {
		
		sentenceDao.batchInsert(setences);
	}
	@Override
	@Transactional
	public void batchInsertSentence(List<String> list)throws Exception {
		List<Sentence> sentenceList =null;
		if(list != null && list.size()>0){
			sentenceList = new ArrayList<Sentence>();
			for (String content : list) {
				Sentence sentence = new Sentence();
				sentence.setContent(content);
				sentence.setType("1");
				sentenceList.add(sentence);
			}
			sentenceDao.batchInsert(sentenceList);
		}
		
		
	}
	@Override
	public PageUtil<Sentence> findSentencesByPage(PageUtil<Sentence> vo) throws Exception {
		String totalDataConut = iSentenceDao.findSentencesCount();
		if(CommonUtils.isNotEmpty(totalDataConut)){
			vo.setTotalDataCount(Integer.parseInt(totalDataConut));
			vo.initTotalPageCount();
			List<Sentence> sentences = iSentenceDao.findSentencesByPage(vo);
			if(sentences != null && sentences.size()>0){
				vo.setList(sentences);
			}
		}
		
		return vo;
	}

}
